package cn.fl.settlement.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapCstStmApplyQC;
import cn.fl.capital.condition.CapCstStmScheduleQC;
import cn.fl.capital.condition.CapFundQueryCondition;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.constant.SettleConstant;
import cn.fl.capital.dto.CapCstStmApplyDTO;
import cn.fl.capital.service.ICapFundService;
import cn.fl.capital.vo.CapFundVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.settlement.service.ISettlementService;
import cn.fl.settlement.vo.CapCstStmApplyVO;
import cn.fl.settlement.vo.CapCstStmScheduleVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import fl.ass.facade.constant.InterfaceConstants;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

/**
 * @Description: 结清Controller控制层(页面参考：资金管理-来款管理)
 * @Author: judahan
 * @CreateDate: 2019/3/12 16:32
 * @Version: 1.0
 */
@Controller
@RequestMapping("/settlement")
public class SettlementController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(SettlementController.class);

    @Autowired
    private ISettlementService settlementService;

    @Autowired
    private ISysDictionaryApiService dictionaryApiService;

    @Autowired
    private ICapFundService capFundService;

    @Autowired
    private IFlowQueryApiService flowQueryApiService;

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/flowInitList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object flowInitList(HttpServletRequest request, HttpServletResponse response) {
        String applyId = request.getParameter("applyId");

        if(StringUtils.isEmpty(applyId)){
            ListPageVO<CapCstStmScheduleVO> listPage = new ListPageVO<CapCstStmScheduleVO>(new ArrayList<CapCstStmScheduleVO>(), 0);
            return listPage;
        }

        CapCstStmScheduleQC capCstStmScheduleQC = new CapCstStmScheduleQC();
        capCstStmScheduleQC.setApplyId(Long.valueOf(applyId));

        List<CapCstStmScheduleVO> list = settlementService.selectCapCstStmScheduleByCondition(capCstStmScheduleQC);
        ListPageVO<CapCstStmScheduleVO> listPage = new ListPageVO<CapCstStmScheduleVO>(list, list.size());
        return listPage;
    }

    /**
     * 流程记录
     */
    @RequestMapping(value = "/toFlowListPage.do", method = { RequestMethod.GET})
    public ModelAndView toFlowListPage(HttpServletRequest request, HttpServletResponse response) {
        String applyId = request.getParameter("id");
        ModelAndView view = new ModelAndView("settlement/flowList");
        view.addObject("applyId", applyId);
        return view;
    }

    /**
     * 到结清列表页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载结清列表页面" + CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView modelAndView = new ModelAndView("settlement/settlementList");
        //结清申请记录状态
        List<KeyValueVO> stsCdList = this.dictionaryApiService.getKvList(SettleConstant.CODE_STM_APPLY_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        //是否需退款
        List<KeyValueVO> isRefundList = this.dictionaryApiService.getKvList(DictionaryConstant.CODE_SYS_YES_NO_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());

        modelAndView.addObject("stsCdList", JSON.toJSONString(stsCdList));
        modelAndView.addObject("isRefundList", JSON.toJSONString(isRefundList));
        return modelAndView;
    }

    /**
     * 初始化列表
     * @param request
     * @param capCstStmApplyQC
     * @return
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initList(HttpServletRequest request, CapCstStmApplyQC capCstStmApplyQC) {
        BaseLogUtils.newLogger("初始化结清列表,参数：capCstStmApplyQC" + JSON.toJSONString(capCstStmApplyQC)).info();
        capCstStmApplyQC.setId(capCstStmApplyQC.getOrderId());
        if (StringUtils.isEmpty(capCstStmApplyQC.getStlSource())) {
            capCstStmApplyQC.setStlSource(null);
        }
        // 按创建时间倒序
        capCstStmApplyQC.setSortName("CRT_TM");
        capCstStmApplyQC.setSortOrder("DESC");
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");

        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        page.setCondition(capCstStmApplyQC);
        BaseLogUtils.newLogger("初始化结清列表页面数据.DATA:" + JSONObject.toJSONString(page)).info();
        Pager pager = null ;
        List<CapCstStmApplyVO> list=null;
        ListPageVO<CapCstStmApplyVO> listPage = null;
        try{
            pager = settlementService.searchListPage(page);
            if(pager!=null){
                list = (List<CapCstStmApplyVO>) pager.getResultList();
            }

            listPage = new ListPageVO<CapCstStmApplyVO>(list, pager.getTotalCount());
        }catch (Exception e){
            BaseLogUtils.newLogger("初始化CapFund列表页面数据异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
        }

        return listPage;
    }

    /**
     * 初始化资金记录列表
     * @param id
     * @return
     */
    @RequestMapping("/capFundInitList.do")
    @ResponseBody
    public ListPageVO capFundInitList(Long id){
        BaseLogUtils.newLogger("初始化结清资金记录列表开始,参数：结清记录id" + JSON.toJSONString(id)).info();
        ListPageVO res = null;
        try {
            //根据“结清申请记录id”查询结清申请信息
            CapCstStmApplyDTO capCstStmApplyDTO = settlementService.selectById(id);
            if (capCstStmApplyDTO == null) {
                return new ListPageVO(Lists.newArrayList(), 0);
            }

            CapFundQueryCondition qc = new CapFundQueryCondition();
            qc.setCstId(capCstStmApplyDTO.getApplyCstId());
            qc.setRelationPayId(capCstStmApplyDTO.getId());
            qc.setCapTypCd(CapitalConstant.CODE_CAP_TYP_CD_2);//资金类型（CAP0022）1.租金、2.结清款、3.首期款、4.风险保证金、5.拖车费、6.其他资金
            List<CapFundVO> list = capFundService.searchList(qc);

            res = new ListPageVO(list, list.size());
        } catch (Exception e) {
            BaseLogUtils.newLogger("初始化结清CapFund列表页面数据异常cause：").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
        }
        return res;
    }

    /**
     * 校验申请状态
     * @param request
     * @return
     */
    @RequestMapping(value = "/checkStatus.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object checkStatus(HttpServletRequest request) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        try {
            // 支付表ID
            String paySchId = request.getParameter("paySchId");
            // 流程实例ID
            String processInstanceId = request.getParameter("procInstId");
            // 流程分支key
            String branchKey = request.getParameter("branchKey");

            // FLOW_00000001_063_001_001_001：财务审核通过
            // FLOW_00000001_063_001_001_002：财务审核不通过
            // FLOW_00000001_063_001_018_001：自动审核异常[处理]
            // FLOW_00000001_063_001_018_002：自动审核异常[核查无误]
            // 只有以上节点操作时，用户可以取消，为了防止用户取消后，流程操作人员不知道，此处得校验申请状态
            // 不是以上节点的操作，直接返回
            if (!("FLOW_00000001_063_001_001_001".equals(branchKey)
                    || "FLOW_00000001_063_001_001_002".equals(branchKey)
                    || "FLOW_00000001_063_001_018_001".equals(branchKey)
                    || "FLOW_00000001_063_001_018_002".equals(branchKey))) {
                result.setData(true);
                return result;
            }

            CapCstStmApplyDTO capCstStmApplyDTO = settlementService.queryByPaySchIdAndProcId(Long.valueOf(paySchId), processInstanceId);
            if (capCstStmApplyDTO == null) {
                throw new BaseException("结清申请信息不存在，无法校验申请状态！");
            }
            // 如果是FLOW_00000001_063_001_018_002：自动审核异常[核查无误]，并且订单没有关闭，则直接返回
            if ("FLOW_00000001_063_001_018_002".equals(branchKey)
                    && !SettleConstant.CODE_SETT_CLOSE.equals(capCstStmApplyDTO.getStsCd())) {
                result.setData(true);
                return result;
            }
            // 如果当前状态不是财务审核中或自动审核中，则无权进行审核订单
            if (!(SettleConstant.CODE_SETT_FINANCE.equals(capCstStmApplyDTO.getStsCd())
                    || SettleConstant.CODE_SETT_AUTO_EXAMINE.equals(capCstStmApplyDTO.getStsCd()))) {
                throw new BaseException("狮桥在线结清申请单状态已变更，操作失败！");
            } else {
                result.setData(true);
            }
        } catch (BaseException e) {
            BaseLogUtils.newLogger("校验狮桥在线申请状态操作异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(e.getMessage());
            result.setData(false);
        } catch (Exception e) {
            BaseLogUtils.newLogger("校验狮桥在线申请状态操作异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            result.setData(false);
        }
        return result;
    }

    /**
     * 狮桥在线申请结清时，流程附加页面跳转
     * 查询是提前结清还是正常结清，实现跳转不同的链接
     * @param request
     * @param redirectAttributes
     * @return
     */
    @RequestMapping(value = "/jumpExtraFlowPage.do", method = {RequestMethod.GET})
    public String jumpExtraFlowPage(HttpServletRequest request, RedirectAttributes redirectAttributes) {
        String url = "";
        try {
            String paySchId = request.getParameter("paySchId");
            String procId = request.getParameter("processInstanceId");
            // 狮桥在线结清附加页面跳转标识
            String onlinePageType = request.getParameter("onlinePageType");

            CapCstStmApplyQC capCstStmApplyQC = new CapCstStmApplyQC();
            capCstStmApplyQC.setPaySchId(Long.valueOf(paySchId));
            capCstStmApplyQC.setProcId(procId);
            List<CapCstStmApplyDTO> capCstStmApplyDTOS = settlementService.searchList(capCstStmApplyQC);
            if (CollectionUtils.isEmpty(capCstStmApplyDTOS)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601, "结清申请单信息未找到！");
            }
            CapCstStmApplyDTO capCstStmApplyDTO = capCstStmApplyDTOS.get(0);
            if (SettleConstant.CODE_SETT_TYPE_NORMAL.equals(capCstStmApplyDTO.getTypeCd())) {
                if ("flow".equals(onlinePageType)) {
                    url = "redirect:/project/prjprdpayschm/settleFlowPage.do";
                } else {
                    url = "redirect:/project/prjprdpayschm/settleAddFeePage.do";
                }
            } else if (SettleConstant.CODE_SETT_TYPE_ADVANCE.equals(capCstStmApplyDTO.getTypeCd())) {
                if ("flow".equals(onlinePageType)) {
                    url = "redirect:/project/prjprdpayschm/preSettleFlowPage.do";
                } else {
                    url = "redirect:/project/prjprdpayschm/addPreSettleFeePage.do";
                }
            }
            // 移除狮桥在线结清跳转附加页面特有的参数
            request.removeAttribute("onlinePageType");
            Enumeration enu = request.getParameterNames();
            while (enu.hasMoreElements()) {
                String paraName = (String) enu.nextElement();
                redirectAttributes.addAttribute(paraName, request.getParameter(paraName));
            }
        } catch (BaseException e) {
            BaseLogUtils.newLogger("狮桥在线结清，流程附加页面跳转失败").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception e) {
            BaseLogUtils.newLogger("狮桥在线结清，流程附加页面跳转失败").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
        }
        return url;
    }

    @RequestMapping(value = "/queryFlowData.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object queryFlowData(HttpServletRequest request) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        try {
            // 流程实例ID
            String processInstanceId = request.getParameter("procId");
            if (StringUtils.isEmpty(processInstanceId)) {
                throw new BaseException("流程实例ID不能为空！");
            }
            String type = request.getParameter("type");
            if (StringUtils.isEmpty(type)) {
                throw new BaseException("类型不能为空！");
            }

            SysFlowSHQueryCondition flowQc = new SysFlowSHQueryCondition();
            if ("1".equals(type)) {
                flowQc.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
            } else if ("2".equals(type)) {
                flowQc.setWordsInTheTable(InterfaceConstants.ASS_FLOW_S_H_ASS);
            } else {
                throw new BaseException("未定义类型！");
            }
            flowQc.setpInstId(processInstanceId);
            flowQc.setSysCd(CurrentThreadContext.getCurrentSysCd());

            List<SysFlowSHDTO> flowSHList = flowQueryApiService.searchFlowSHList(flowQc);
            if (CollectionUtils.isEmpty(flowSHList)) {
                throw new BaseException("未找到流程历史记录！");
            }
            JSONObject json = wrapFlowData(flowSHList.get(0));
            result.setData(json);
        } catch (BaseException e) {
            BaseLogUtils.newLogger("查询流程历史数据异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(e.getMessage());
        } catch (Exception e) {
            BaseLogUtils.newLogger("查询流程历史数据异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
        }
        return result;
    }

    /**
     * 进入试算结清IRR页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/toTrialIRRPage.do", method = { RequestMethod.GET})
    public ModelAndView toTrialIRRPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("settlement/trialIRRPage");
        return view;
    }

    /**
     * 试算结清IRR
     * @param request
     * @return
     */
    @RequestMapping(value = "/trialIRR.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object trialIRR(HttpServletRequest request) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        try {
            String paySchNo = request.getParameter("paySchNo");
            if (StringUtils.isEmpty(paySchNo)) {
                throw new BaseException("支付表编号不能为空！");
            }
            String amount = request.getParameter("amount");
            if (StringUtils.isEmpty(amount)) {
                throw new BaseException("金额不能为空！");
            }
            Long amountFen = null;
            try {
                amountFen = DecimalUtils.convertYuanToFen(Double.valueOf(amount));
            } catch (NumberFormatException e) {
                throw new BaseException("请输入正确的金额！");
            }
            String dateStr = request.getParameter("trialDate");
            if (StringUtils.isEmpty(dateStr)) {
                throw new BaseException("时间不能为空！");
            }
            Date date = null;
            try {
                date = DateUtils.formatStringToDate(dateStr, DateUtils.YYYY_MM_DD);
            } catch (Exception e) {
                throw new BaseException("请输入正确的时间，格式为：" + DateUtils.YYYY_MM_DD);
            }
            Map<String, Object> trialMap = settlementService.trialSettleIRRData(paySchNo, amountFen, date);
            /*
            analyseMap.put("inCash", inMap);
            analyseMap.put("outCash", outMap);
            analyseMap.put("actIrr", actIrr);// 实际IRR
            analyseMap.put("irrConfig", irrConfig);// 结清IRR配置
            analyseMap.put("historyRepayNPV", historyRepayNPV);
            analyseMap.put("actRepay", actRepay);
            analyseMap.put("irr", irr);
            analyseMap.put("discountAmtIRR", discountAmtIRR);*/
            result.setData(trialMap);
        } catch (BaseException e) {
            BaseLogUtils.newLogger("试算结清IRR异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(e.getMessage());
        } catch (Exception e) {
            BaseLogUtils.newLogger("试算结清IRR异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
        }
        return result;
    }

    private JSONObject wrapFlowData(SysFlowSHDTO flow) {
        /*
         FLOW_00000001_011_001 重卡正常结清     /project/prjprdpayschm/settleAddFeePage.do?isDetail=1@@processInstanceId=" + _pInstId + "@@paySchId=
         FLOW_00000008_011_001 专车客车正常结清 /project/prjprdpayschm/settleAddFeePage.do?isDetail=1@@processInstanceId=8d88d99c-61a7-11ea-ac9b-0894ef2526f3@@paySchId=
         FLOW_00000009_011_001 优车正常结清    /project/prjprdpayschm/settleAddFeePage.do?isDetail=1@@processInstanceId=b3e46b6a-6f1c-11ea-b898-0894ef2526f3@@paySchId=
         FLOW_00000013_011_001 新能源正常结清  /project/prjprdpayschm/settleAddFeePage.do?isDetail=1@@processInstanceId=a09246ae-0b3e-11ea-b0ba-0894ef059c98@@paySchId=
         FLOW_00000001_012_001 重卡提前结清     /project/prjprdpayschm/addPreSettleFeePage.do?isDetail=1@@processInstanceId=" + _pInstId + "@@paySchId=
         FLOW_00000008_012_002 专车客车提前结清 /project/prjprdpayschm/addPreSettleFeePage.do?isDetail=1@@processInstanceId=d8dbcc3c-6b15-11ea-b898-0894ef2526f3@@paySchId=
         FLOW_00000009_012_001 优车提前结清    /project/prjprdpayschm/addPreSettleFeePage.do?isDetail=1@@processInstanceId=5b70fd27-6ffa-11ea-b898-0894ef2526f3@@paySchId=
         FLOW_00000013_012_001 新能源提前结清  /project/prjprdpayschm/addPreSettleFeePage.do?isDetail=1@@processInstanceId=cf6d3fe9-6e4a-11ea-b898-0894ef2526f3@@paySchId=

         FLOW_00000005_011_001 汽车金融正常结清 /project/prjprdpayschm/settleCarNormalAddFeePage.do?isDetail=1@@processInstanceId=f9368e8f-6fd9-11ea-b898-0894ef2526f3@@paySchId=
         FLOW_00000005_012_001 汽车金融提前结清 /project/prjprdpayschm/addCarPreSettleFeePage.do?isDetail=1@@processInstanceId=eb850249-6f2f-11ea-a591-0894ef619ece@@paySchId=

         FLOW_00000001_063_001 狮桥在线结清    /settlement/jumpExtraFlowPage.do?onlinePageType=flow@@processInstanceId="+pinstId+"@@paySchId=
         FLOW_0000_065_001     资管结清       /project/financialInst/showZGSettlePage.do?bankAct=1-1-1-1@@processInstanceId=2a5dc6d5-6ff9-11ea-b898-0894ef2526f3@@paySchId=
         */
        String defKey = flow.getPDefKey();
        String formUrl = "";
        if ("FLOW_0000_065_001".equals(defKey)) { // 资管结清
            formUrl = "/project/financialInst/showZGSettlePage.do?bankAct=1-1-1-1@@processInstanceId=%s@@paySchId=";
        } else if ("FLOW_00000005_011_001".equals(defKey)) { // 汽车金融正常结清
            formUrl = "/project/prjprdpayschm/settleCarNormalFlowPage.do?showBk_oCIn=1@@isDetail_bk=1@@showBk_oCOut=1@@processInstanceId=%s@@paySchId=";
        } else if ("FLOW_00000005_012_001".equals(defKey)) { // 汽车金融提前结清
            formUrl = "/project/prjprdpayschm/carPreSettleFlowPage.do?showBk_oCIn=1@@isDetail_bk=1@@showBk_oCOut=1@@processInstanceId=%s@@paySchId=";
        } else if ("FLOW_00000001_063_001".equals(defKey)) { // 狮桥在线结清
            formUrl = "/settlement/jumpExtraFlowPage.do?onlinePageType=flow@@processInstanceId=%s@@paySchId=";
        } else if ("FLOW_0000_STL001_001".equals(defKey)) { // 结清通用流程
            formUrl = "/settlement/bill/toAuditPage.do?processInstanceId=%s@@paySchId=";
        } else if (defKey.contains("_011_")) { // 正常结清流程(重卡、专车客车、优车、新能源)
            formUrl = "/project/prjprdpayschm/settleAddFeePage.do?isDetail=1@@processInstanceId=%s@@paySchId=";
        } else if (defKey.contains("_012_")) { // 提前结清流程(重卡、专车客车、优车、新能源)
            formUrl = "/project/prjprdpayschm/addPreSettleFeePage.do?isDetail=1@@processInstanceId=%s@@paySchId=";
        }
        // 替换%s
        formUrl = String.format(formUrl, flow.getPInstId());

        JSONObject json = new JSONObject();
        json.put("audStsCd", flow.getAudStsCd());
        json.put("dataId", flow.getDataId());
        json.put("pno", flow.getPNo());
        json.put("formUrl", formUrl);
        return json;
    }

}

